#include "clean/test/TestClean.h"
#include "clean/Clean.h"
#include "clean/Spectrum.h"
#include "clean/SpectrumProcessing.h"

#include "core/TimeSeries.h"

#include <complex>
#include <iostream>

using namespace spectClean;

/**
 * @details
 */
void TestClean::test()
{
    std::cout << std::endl;
    std::cout << "===========================================" << std::endl;

    typedef SpectrumComponent fc;
    SpectrumProcessing sp;
    Clean c;

    TimeSeries t;
    std::vector<fc> components;
    components.push_back(fc(1.0, 5.0));
    components.push_back(fc(0.5, 10.0));
    t.generateRandom(200, 0.0, 2.0, components);
    //t.generateEven(100, 0.0, 2.0, components);

    Spectrum ds;
    sp.dirtySpectrumDFT(t, ds, 30.0, 20);

    Spectrum ws;
    sp.windowSpectrumDFT(t, ws, 60.0, 20);

    std::cout << "ws.size() : " << ws.size() << std::endl;
    std::cout << "ds.size() : " << ds.size() << std::endl;

    Spectrum cc;
    Spectrum residual;
    residual = ds;

    cc.resize(residual.size());
    cc.freq() = ds.freq();
    const unsigned num_iterations = 30;
    const double gain = 0.7;

    c.simpleClean(ws, cc, residual, num_iterations, gain);

    ds.save("test_ds.txt");
    ws.save("test_ws.txt");
    cc.save("test_cc.txt");
    residual.save("test_r.txt");
    std::cout << "===========================================" << std::endl;
}

